package lk.week02;

import commons.ListNode;

/**
 * ClassName: P0876_MiddleNode
 * Description:
 * Author: xyf
 * Date: 5/20/23 11:10 PM
 * Version: 1.0
 **/
public class P0876_MiddleNode
{
    public ListNode middleNode(ListNode head)
    {
        if (head == null || head.next == null)
        {
            return head;
        }

        ListNode slow = head;
        ListNode fast = head;
        while (fast != null && fast.next != null)
        {
            fast = fast.next.next;
            slow = slow.next;
        }
        return slow;
    }
}